﻿using System;

namespace gt.framework.Utils
{
    public static class DateTimeUtils
    {
        public static long ToUnixTimestamp(DateTime source)
        {
            TimeSpan span = (source - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());
            return (long)span.TotalSeconds;
        }

        public static DateTime ToDateTime(long timestamp)
        {
            DateTime converted = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            DateTime newDateTime = converted.AddSeconds(timestamp);
            return newDateTime.ToLocalTime();
        }
    }
}
